﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>预览Amis页面</title>
    <link rel="stylesheet" href="/sdk/sdk.css" />
    <script src="/sdk/sdk.js"></script>
    <script src="/jslib/jsonpath.min.js"></script>
    <script src="/jslib/jquery-3.4.1.min.js"></script>
    <script src="/jslib/lobster.js"></script>
    <style>
        html,
        body,
        .app-wrapper {
            position: relative;
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
        }
    </style>
</head>
<body>
    <div id="root" class="app-wrapper"></div>
</body>
</html>

<script type="text/javascript">

    //var pagejson = @Html.Raw(ViewData["pagedata"].ToString());

    lobstercommon.name = "lobsteramis";
    var appid = lobstercommon.GetUrlParam("appid");
    var id = lobstercommon.GetUrlParam("id");
    let amislib = amisRequire('amis');
    let amis = amisRequire('amis/embed');

    (function () {

        

        try {
            //@Html.Raw(ViewData["pagescript"])

            lobstercommon.GET('/amis/v1/amisdata/openamis', {appid:appid,id:id}).then(data => {
                var pagejson = JSON.parse(data["pagedata"]);

                //给所有请求加上headers
                //Amis的接口请求必须配置高级模式，不然无法替换headers，就无法传递token
                //没有headers那就只支持匿名函数
                var headers = lobsteramis.GetHeaderData();
                var apiList = jsonpath.query(pagejson, '$..api');
                apiList.forEach(item => {
                    if (item.url) {
                        item.headers = headers;
                    }
                })
                lobsteramis.run(jsonpath, amislib, pagejson);

                //执行脚本
                var pagescript = data["pagescript"];
                eval(pagescript);
                // 通过替换下面这个配置来生成不同页面
                let amisScoped = amis.embed('#root', pagejson);
            })

        } catch (e) {
            console.log(e);
        }
        
    })();
</script>